﻿# // ***************************************************************************
# // 
# // Copyright (c) Scriptimus Ex Machina.  All rights reserved.
# // 
# // Microsoft Deployment Toolkit Support Script
# //
# // File:      ZTINew-User.ps1
# // 
# // Version:   1.00 
# // 
# // Purpose:   Create a new user in Active Directory
# // 
# // ***************************************************************************

<#
.SYNOPSIS 
Create a New Active Directory User Account and adds it to the Domain Admins group

.DESCRIPTION
The ZTINew-User.ps1 script will create a new Active Directory user account and add it to the Domain Admins group.
    
.PARAMETER Name
Specifies the new user account name.

.PARAMETER Password
Specifies the Password for the new user account.

.PARAMETER Description
Specifies a description for the new user account.

.EXAMPLE
.\ZTINew-User Andrew 
This will create a new user called Andrew.

.NOTES
Author: Andrew Barnes
Date: 17 September 2012

.LINK
Online version: http://scriptimus.wordpress.com
            
#>

Param (

     [String]$User = "User1",

     [String]$Password = "qwert@12345"

    )

Begin {

    Write-Host "Begining script"

    Import-Module ActiveDirectory

    }

Process {
    
    Write-Host "Processing Script"

    # Create New AD User

    Write-Host "Creating AD User: $User" 

    New-ADUser -Name $User -DisplayName $User -PasswordNeverExpires $true -ChangePasswordAtLogon $false -Verbose


    # Set Password

    Write-Host "Setting Password for user: $User"

    Set-ADAccountPassword $User -NewPassword (ConvertTo-SecureString -AsPlainText $Password -Force) -Verbose

    
    # Enable User Account

    Write-Host "Enabling User Account: $User"

    Enable-ADAccount $User -Verbose


    # Add User to Domain Admins Group

    Write-Host "Adding user: $User to Domain Admins Group"

    Add-ADGroupMember -Identity 'Domain Admins' -Members $User

    }

End {
    
    Write-Host "End Script"
    
    }